/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package xin.alum.aim.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.protobuf.MessageLite;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCounted;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import lombok.Data;

/**
 * 需要向另一端发送的结构体
 */
@Data
public abstract class Transportable extends AbstractReferenceCounted {
    private static final long serialVersionUID = 1L;

    @JsonIgnore
    protected final InternalLogger logger = InternalLoggerFactory.getInstance(this.getClass());

    /**
     * 消息处理优先级
     */
    private int priority = 0;

    /**
     * 时间戳
     */
    private long timestamp = System.currentTimeMillis();

    /**
     * 消息体字节数组
     *
     * @return
     */
    public abstract byte[] getBody();

    /**
     * 消息类型，请参阅AIMConstant.DATA_TYPE_****
     *
     * @return
     */
    public abstract int getType();

    /**
     * proto 对象
     *
     * @return
     */
    public abstract MessageLite toBuilder();


    @Override
    protected void deallocate() {
//        logger.warn("开始回收对象{}, 此时的引用数是:{}", this.getClass(), this.refCnt());
    }

    @Override
    public ReferenceCounted touch(Object o) {
        return this;
    }
}
